package org.winexpress

class AwsSesController {

    def sesTestService

//    def sendPlainTextMail = { 
//	
//        def mailId = sesMail {
//            to "puchirin@gmail.com"
//            subject "test plain text mail"
//            body "sendPlainTextMail (${new Date().format('dd/MM/yyyy HH:mm')})"
//        }
//		
//        render "E-mail sent: ${mailId}"
//    }

    def sendPlainTextMailFromService = { 
	
        def mailId = sesTestService.sendTestMail()
		
        render "E-mail sent: ${mailId}"
    }
    
    def sendPlainTextMail = { 
//        def emailAddr = params['email']
//        def subject = params['subject']
//        def firstName = params['firstName']
//        def pw = params['pw']
//        def activationURL = params['activationURL']
	
        def mailId = sesMail {
            to "puchirin@gmail.com"
            subject "test plain text mail"
            body "sendPlainTextMail (${new Date().format('dd/MM/yyyy HH:mm')})"
        }
		
        render "E-mail sent: ${mailId}"
    }
    

    // sendHtmlMail
    def sendHtmlMailFromTemplate = {
        String emailAddr = params['email']
        String subj = params['subject']
        String firstName = params['firstName']
        String un = params['un']
        String pw = params['pw']
        String activationURL = params['activationURL']
        
        println createLinkTo(dir:"images", file:"logo.jpg").toString()

        def mailId = sesMail {
            to emailAddr
            subject subj
            html g.render(template: "/email-templates/template", model: [name: firstName, username:un, password: pw, activateLink: activationURL, now: new Date()])
        }
		
        render "E-mail sent: ${mailId}"
    }  
}
